﻿package _3_Panel;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
/**
 * 2011-6-4 16:17:06
 * @author Administrator
 */
public class TJScrollPane {
    JFrame frame;
    Container contentPane;
    JScrollPane jsp;
    JButton nextBun;
    JTextArea jta[];
    public TJScrollPane(){
        frame=new JFrame("JScrollPane测试");
        contentPane=frame.getContentPane();
        contentPane.setLayout(new BorderLayout());
        jta=new JTextArea[4];
        for(int i=0;i<jta.length;i++){
            jta[i]=new JTextArea(10,40);
            char c[]=new char[100];
            Arrays.fill(c, (char)(i+'0'));
            jta[i].setText(new String(c));
            jta[i].setLineWrap(true);
        }
        jsp=new JScrollPane(jta[0]);
        jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        contentPane.add(jsp,BorderLayout.CENTER);
        nextBun=new JButton("下一个");
        nextBun.addActionListener(new ActionListener(){
            int tip=0;
            public void actionPerformed(ActionEvent e) {
                tip++;
                tip%=4;
                jsp.setViewportView(jta[tip]);
            }
        });
        contentPane.add(nextBun,BorderLayout.SOUTH);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public static void main(String args[]){
        new TJScrollPane();
    }
}
